Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

264
Visualizações
JavaScript cancel "mouseleave" event on "click"

I'm working on a problem where I'm not able to find a solution. I'm still a beginner though. Here the code:

var navContact = document.getElementsByClassName("nav-l")[0];
var contactForm = document.getElementsByClassName("kontakt")[0];

var navContactMouseEnter = function (e) {
  console.log("mouse entered!");
  navContact.style.paddingLeft = "5vw";
  contactForm.style.transform = "translateX(-25vw)";
}

var navContactMouseLeave = function (e) {
  console.log("mouse left!");
  navContact.style.paddingLeft = "0vw";
  contactForm.style.transform = "translateX(-31vw)";
}

navContact.addEventListener("mouseenter", navContactMouseEnter, true);
navContact.addEventListener("mouseleave", navContactMouseLeave, true);

navContact.addEventListener("click", (e) => {
  e.preventDefault();
  navContact.removeEventListener("mouseleave", navContactMouseLeave, true);
  navContact.style.paddingLeft = "5vw";
  contactForm.style.transform = "translateX(0vw)";
});

I'm trying to get a little slideIn Animation on "mouseenter" but on "click" that element should slideout completely and ignore any "mouseleave" event. There I'm faceing the issues... I'm not able to cancel the "mouseleave" event. That element should only disappear when I click on "X" - but thats no problem.

I'm grateful for any help.

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Ok, after breaking my head for couple more hours I found out, that I also needed to do this:

navContact.removeEventListener("mouseenter", navContactMouseEnter, true);

I also got different styles on the mouseenter-event, which pulled the element back again.

Lesson learned :D

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda